package {
import com.lushu.chapitre1.data.database.ItemDatabase;
import com.lushu.chapitre1.data.enums.ConnectivityMode;
import com.lushu.chapitre1.states.GameInitState;
import com.lushu.chapitre1.states.LoadDataState;

import com.sfdk.core.GameProxy;

    import flash.display.StageDisplayState;
    import flash.events.ContextMenuEvent;

    import flash.events.Event;
    import flash.geom.Matrix;
    import flash.geom.Rectangle;
    import flash.geom.Transform;
    import flash.ui.ContextMenu;
    import flash.ui.ContextMenuItem;


[Frame(factoryClass="com.sfdk.core.BasicPreloader")]
[SWF(width="496", height="448", frameRate="200")]
public class GameMain extends GameProxy
{
    public function GameMain() {
        super();
        addEventListener(Event.ADDED_TO_STAGE, onAddedToStage, false, 0, true);

    }

    private var _itemDatabase:ItemDatabase;

    public function get itemDatabase():ItemDatabase {
        return _itemDatabase;
    }

    public function set itemDatabase(value:ItemDatabase):void {
        _itemDatabase = value;
    }

    private var _connectivityMode:ConnectivityMode;

    public function get connectivityMode():ConnectivityMode {
        return _connectivityMode;
    }

    public function set connectivityMode(value:ConnectivityMode):void {
        _connectivityMode = value;
    }

    //private var _loadingScreen : LoadingScreen;


    /** Event Listeners **/

    private function onAddedToStage(e:Event):void {
        setState(LoadDataState, null);
        this.contextMenu = new ContextMenu();
        var fullScreenItem : ContextMenuItem = new ContextMenuItem("Fullscreen");
        fullScreenItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onFullScreenMode);
        contextMenu.customItems.push(fullScreenItem);
    }

    private function onFullScreenMode(e : ContextMenuEvent) : void
    {
        stage.fullScreenSourceRect = new Rectangle(0,0,496,448);
        stage.displayState = StageDisplayState.FULL_SCREEN;
    }

    public override function setState(newStateClass:Class, parameters:Object):void {
        /*_loadingScreen = new LoadingScreen(672, 558);
         attachChild(_loadingScreen);*/
        super.setState(newStateClass, parameters);
    }

    public override function stateLoaded():void {
        //removeChild(_loadingScreen);
    }
}
}
